package com.study.d012Components;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * TitledPane 和  Accordion 的使用
 * TitledPane: 标题面板，可以展开收放
 * Accordion ：将多个TitledPane放在一起，也是可以自动展开和收放
 * @author Administrator
 *
 */
public class TitledPaneMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}
	@Override
	public void start(Stage stage) throws Exception {
		TitledPane tp1 =new TitledPane("设置",new Button("测试1"));
		tp1.setContent(new Button("测试2"));

		TitledPane tp2 = new TitledPane();
		tp2.setText("设置2");
		tp2.setContent(new Button("测试2") );


		VBox vb = new VBox();
		vb.getChildren().addAll(new Button("测试1"),new Button("测试2"),new Button("测试3"),new Button("测试4"));

		TitledPane tp3 = new TitledPane();
		tp3.setText("设置3");
		tp3.setContent(vb);



		AnchorPane ap = new AnchorPane();
		AnchorPane.setTopAnchor(tp1, 1.0);
		AnchorPane.setTopAnchor(tp2, 90.0);
		AnchorPane.setLeftAnchor(tp3, 100.0);

		ap.getChildren().addAll(tp1,tp2,tp3);

		//监听tp1的展开事件
		tp1.expandedProperty().addListener(new ChangeListener<Boolean>() {
			@Override
			public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
				System.out.println(oldValue);
				System.out.println(newValue);
			}

		});


		//Accordion的使用



		TitledPane tp4 =new TitledPane("设置4",new Button("测试4"));
		TitledPane tp5 =new TitledPane("设置5",new Button("测试5"));
		TitledPane tp6 =new TitledPane("设置6",new Button("测试6"));

		Accordion ac  =new Accordion(tp4,tp5,tp6);
		AnchorPane.setLeftAnchor(ac, 200.0);
		ap.getChildren().add(ac);

		//Accordion添加监听事件
		ac.expandedPaneProperty().addListener(new ChangeListener<TitledPane>() {

			@Override
			public void changed(ObservableValue<? extends TitledPane> observable, TitledPane oldValue,
					TitledPane newValue) {
				if(oldValue !=null){
					System.out.println("当前展开的是：" + oldValue.getText());
				}else{
					System.out.println("当前关闭的是:" + newValue.getText());
				}
			}

		});

		stage.setScene(new Scene(ap));
		stage.setWidth(400);
		stage.setHeight(300);
		stage.show();


	}
}
